package com.ltmonitor.web.controller.video;

import com.ltmonitor.entity.TerminalCommand;
import com.ltmonitor.entity.VehicleData;
import com.ltmonitor.service.IOnlineVideoRequestService;
import com.ltmonitor.service.ITerminalVideoPropertyService;
import com.ltmonitor.util.StringUtil;
import com.ltmonitor.util.VideoDataType;
import com.ltmonitor.video.entity.TerminalVideoProperty;
import com.ltmonitor.video.entity.VideoRequest;
import com.ltmonitor.video.entity.VideoServerConfig;
import com.ltmonitor.web.constants.FunctionConstant;
import com.ltmonitor.web.controller.command.TerminalCommandAction;
import com.ltmonitor.web.util.JsonMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 下发监听命令
 * 
 * @author DELL
 * 
 */
@Controller
@RequestMapping("/videoCommand")
public class VideoCommandAction extends TerminalCommandAction {
	@Autowired
	private IOnlineVideoRequestService onlineVideoRequestService;
	@Autowired
	private ITerminalVideoPropertyService terminalVideoPropertyService;

	
	@RequestMapping("/viewTerminalVideoProperty.action")
	public String viewTerminalVideoProperty(long vehicleId, Model m)
	{
		m.addAttribute("vehicleId", vehicleId);
		return "/video/terminalVideoProperty";
	}


	@RequestMapping("/viewAdjustVideoColor.action")
	public String viewAdjustVideoColor(long vehicleId, Model m)
	{
		m.addAttribute("vehicleId", vehicleId);
		return "/video/adjustVideoDisplay";
	}


	@RequestMapping("/viewHlsPlayer.action")
	public String viewHlsPlayer( Model m)
	{
		return "/video/videoHlsPlayer";
	}

	/**
	 * 打开实时视频页面
	 * @param m
	 * @param vehicleId  如果是报警弹窗，则根据报警的车辆Id, 将车牌号和sim卡号输出到页面当中
	 * @return
	 */
	@RequestMapping("/viewRealTimeVideo.action")
	public String viewRealTimeVideo(Model m,@RequestParam(value = "vehicleId", defaultValue="0") long vehicleId,
									@RequestParam(value = "popupWindow", defaultValue="false") boolean popupWindow)
	{
		if(hasRealTimeVideoAuthority() == false)
			return "/video/noVideoPermission";

		VideoServerConfig vc = this.getVideoServerConfig();
		m.addAttribute("videoServerConfig", vc);
		if(vehicleId > 0)
		{
			VehicleData vd = this.vehicleDataService.load(vehicleId);
			m.addAttribute("simNo", vd.getSimNo());
			m.addAttribute("plateNo", vd.getPlateNo());
			m.addAttribute("plateNo", vd.getPlateNo());
		}
		m.addAttribute("popupWindow", popupWindow);
		m.addAttribute("vehicleId", vehicleId);
		return "/video/realTimeVideo";
	}

	@RequestMapping("/viewListenVideoTerminal.action")
	public String viewListenVideoTerminal(@RequestParam(value = "vehicleId", defaultValue="0") long vehicleId, String simNo,
										  @RequestParam(value = "channelId", defaultValue="0") int channelId, String autoStartType,  Model m)
	{
		if(vehicleId == 0 && StringUtil.isNullOrEmpty(simNo) == false)
		{
			if(simNo.length() > 11)
				simNo = simNo.substring(simNo.length() - 11);
			VehicleData vd = this.vehicleDataService.getVehicleBySimNo(simNo);
			if( vd != null)
				vehicleId = vd.getEntityId();

			m.addAttribute("simNo", simNo);
		}else
		{
			VehicleData vd = this.vehicleDataService.load(vehicleId);
			m.addAttribute("simNo", vd.getSimNo());
		}
		m.addAttribute("channelId", channelId);
		m.addAttribute("autoStartType", autoStartType);
		m.addAttribute("vehicleId", vehicleId);
		return "/video/listenVideoTerminal";
	}


	@RequestMapping("/viewTalkVideoTerminal.action")
	public String viewTalkVideoTerminal(@RequestParam(value = "vehicleId", defaultValue="0") long vehicleId, String simNo,
										@RequestParam(value = "channelId", defaultValue="0")	int channelId, String autoStartType,  Model m)
	{
		if(vehicleId == 0 && StringUtil.isNullOrEmpty(simNo) == false)
		{

			if(simNo.length() > 11)
				simNo = simNo.substring(simNo.length() - 11);
			VehicleData vd = this.vehicleDataService.getVehicleBySimNo(simNo);
			if( vd != null)
				vehicleId = vd.getEntityId();
			m.addAttribute("simNo", simNo);
		}else
		{
			VehicleData vd = this.vehicleDataService.load(vehicleId);
			m.addAttribute("simNo", vd.getSimNo());
		}
		m.addAttribute("channelId", channelId);
		m.addAttribute("autoStartType", autoStartType);
		m.addAttribute("vehicleId", vehicleId);
		return "/video/talkVideoTerminal";
	}


	@RequestMapping("/viewBroadcastVideoTerminal.action")
	public String viewBroadcastVideoTerminal(long vehicleId, Model m)
	{
		m.addAttribute("vehicleId", vehicleId);
		VehicleData vd = this.vehicleDataService.load(vehicleId);
		m.addAttribute("simNo", vd.getSimNo());
		return "/video/broadcastVideoTerminal";
	}

	@RequestMapping("/viewVideoControl.action")
	public String viewVideoControl(long vehicleId, Model m)
	{
		m.addAttribute("vehicleId", vehicleId);
		VehicleData vd = this.vehicleDataService.load(vehicleId);
		m.addAttribute("simNo", vd.getSimNo());
		return "/video/videoControl";
	}


	@RequestMapping("/viewDangerousVideo.action")
	public String viewDangerousVideo(long vehicleId, Model m)
	{
		m.addAttribute("vehicleId", vehicleId);
		VehicleData vd = this.vehicleDataService.load(vehicleId);
		m.addAttribute("simNo", vd.getSimNo());
		return "/video/dangerousVideo";
	}

	/**
	 * 下发实时音视频传输指令
	 * @param simNo sim卡号
	 * @param channel 通道号
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/realTimeVideo.action")
	public JsonMessage realTimeVideo(long vehicleId,String simNo, int channel) {

		if(hasRealTimeVideoAuthority() == false)
			return json(false, "对不起，你没有实时视频监控权限");
		try {
			StringBuilder sb = new StringBuilder();
			String videoServerIp = this.getVideoServerConfig().getVideoServerIp();
			int tcpPort = this.getVideoServerConfig().getVideoServerTcpPort();
			int udpPort = this.getVideoServerConfig().getVideoServerUdpPort();
			int videoDataType = this.getUserPreference().getVideoDataType();// 音视频数据类型  VideoDataType.VIDEO_WITH_AUDIO;
			int stream = this.getUserPreference().getStreamType();//码流类型
			sb.append(videoServerIp).append(';').append(tcpPort).append(';')
					.append(udpPort).append(';').append(channel).append(';')
					.append(videoDataType).append(';').append(stream);

			if(vehicleId == 0 && StringUtil.isNullOrEmpty(simNo) == false)
			{
				if(simNo.length() > 11)
					simNo = simNo.substring(simNo.length() - 11);
				VehicleData vd = this.vehicleDataService.getVehicleBySimNo(simNo);
				if( vd != null)
					vehicleId = vd.getEntityId();
				else
					return json(false, simNo + "没有对应的车辆信息");
			}

			TerminalCommand tc = new TerminalCommand();
			tc.setVehicleId(vehicleId);
			tc.setCmdType(0x9101);
			tc.setCmdData(sb.toString());
			SendCommand(tc);
			String sessionId = this.getSession().getId();
			VideoRequest v = new VideoRequest();
			v.setSimNo(simNo);
			v.setChannelId(channel);
			v.setMediaType(videoDataType);
			v.setStreamType(stream);
			v.setPlateNo(tc.getPlateNo());
			v.setUserIp(this.getRequest().getRemoteAddr());
			v.setUserId(this.getOnlineUser().getEntityId());
			v.setUserName(this.getOnlineUser().getName());
			v.setSessionId(sessionId);
			onlineVideoRequestService.updateVideoRequest(v);

			return json(true, tc.getEntityId());
		} catch (Exception ex) {
			log.error(ex.getMessage(),ex);
			return json(false, ex.getMessage());
		}
	}

	/**
	 * 下发实时音视频传输指令
	 * @param simNo sim卡号
	 * @param channel 通道号
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/listen.action")
	public JsonMessage listen(int vehicleId,String simNo, int channel) {
		try {
			StringBuilder sb = new StringBuilder();
			String videoServerIp = this.getVideoServerConfig().getVideoServerIp();
			int tcpPort = this.getVideoServerConfig().getVideoServerTcpPort();
			int udpPort = this.getVideoServerConfig().getVideoServerUdpPort();
			int videoDataType = VideoDataType.LISTEN;
			int stream = 0;
			sb.append(videoServerIp).append(';').append(tcpPort).append(';')
					.append(udpPort).append(';').append(channel).append(';')
					.append(videoDataType).append(';').append(stream);

			TerminalCommand tc = new TerminalCommand();
			tc.setVehicleId(vehicleId);
			tc.setCmdType(0x9101);
			tc.setCmdData(sb.toString());
			SendCommand(tc);
			String sessionId = this.getSession().getId();
			VideoRequest v = new VideoRequest();
			v.setSimNo(simNo);
			v.setChannelId(channel);
			v.setMediaType(videoDataType);
			v.setStreamType(stream);
			v.setPlateNo(tc.getPlateNo());
			v.setUserIp(this.getRequest().getRemoteAddr());
			v.setUserId(this.getOnlineUser().getEntityId());
			v.setUserName(this.getOnlineUser().getName());
			v.setUserName(this.getOnlineUser().getName());
			v.setSessionId(sessionId);
			onlineVideoRequestService.updateVideoRequest(v);

			return json(true, tc.getEntityId());
		} catch (Exception ex) {
			log.error(ex.getMessage(),ex);
			return json(false, ex.getMessage());
		}
	}

	/**
	 * 下发实时音视频传输控制指令
	 * @param simNo sim卡号
	 * @param channelId 通道号
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/controlRealPlayVideo.action")
	public JsonMessage controlRealPlayVideo(@RequestParam(value = "vehicleId", defaultValue="0") long vehicleId,String simNo, int channelId,
											int controlCmd, @RequestParam(value = "videoDataType", defaultValue="0") int videoDataType, int streamType) {
		try {
			StringBuilder sb = new StringBuilder();
			sb.append(channelId).append(';').append(controlCmd).append(';').append(videoDataType).append(';').append(streamType);
			TerminalCommand tc = new TerminalCommand();
			if(vehicleId == 0 && StringUtil.isNullOrEmpty(simNo) == false)
			{
				if(simNo.length() > 11)
					simNo = simNo.substring(simNo.length() - 11);
				VehicleData vd = this.vehicleDataService.getVehicleBySimNo(simNo);
				if( vd != null)
					vehicleId = vd.getEntityId();
				else
					return json(false, simNo + "没有对应的车辆信息");
			}
			tc.setVehicleId(vehicleId);
			tc.setCmdType(0x9102);
			tc.setCmdData(sb.toString());
			SendCommand(tc);

			return json(true, tc.getEntityId());
		} catch (Exception ex) {
			log.error(ex.getMessage(),ex);
			return json(false, ex.getMessage());
		}
	}
	/**
	 * 下发实时音视频传输指令
	 * @param simNo sim卡号
	 * @param channel 通道号
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/talk.action")
	public JsonMessage talk(int vehicleId,String simNo, int channel) {
		try {
			StringBuilder sb = new StringBuilder();
			String videoServerIp = this.getVideoServerConfig().getVideoServerIp();
			int tcpPort = this.getVideoServerConfig().getVideoServerTcpPort();
			int udpPort = this.getVideoServerConfig().getVideoServerUdpPort();
			int videoDataType = VideoDataType.TALK;
			int stream = 0;
			sb.append(videoServerIp).append(';').append(tcpPort).append(';')
					.append(udpPort).append(';').append(channel).append(';')
					.append(videoDataType).append(';').append(stream);

			TerminalCommand tc = new TerminalCommand();
			tc.setVehicleId(vehicleId);
			tc.setCmdType(0x9101);
			tc.setCmdData(sb.toString());
			SendCommand(tc);
			String sessionId = this.getSession().getId();
			VideoRequest v = new VideoRequest();
			v.setSimNo(simNo);
			v.setChannelId(channel);
			v.setStreamType(stream);
			v.setPlateNo(tc.getPlateNo());
			v.setUserIp(this.getRequest().getRemoteAddr());
			v.setUserId(this.getOnlineUser().getEntityId());
			v.setUserName(this.getOnlineUser().getName());
			v.setSessionId(sessionId);
			v.setMediaType(videoDataType);
			onlineVideoRequestService.updateVideoRequest(v);

			return json(true, tc.getEntityId());
		} catch (Exception ex) {
			log.error(ex.getMessage(),ex);
			return json(false, ex.getMessage());
		}
	}


	/**
	 * 下发实时音视频传输指令
	 * @param simNo sim卡号
	 * @param channel 通道号
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/broadcast.action")
	public JsonMessage broadcast(int vehicleId,String simNo, int channel, String allSelectedVehicle) {
		try {
			StringBuilder sb = new StringBuilder();
			String videoServerIp = this.getVideoServerConfig().getVideoServerIp();
			int tcpPort = this.getVideoServerConfig().getVideoServerTcpPort();
			int udpPort = this.getVideoServerConfig().getVideoServerUdpPort();
			int videoDataType = VideoDataType.BROADCAST;
			int stream = 0;//语音状态下码流无效
			sb.append(videoServerIp).append(';').append(tcpPort).append(';')
					.append(udpPort).append(';').append(channel).append(';')
					.append(videoDataType).append(';').append(stream);

			String sessionId = this.getSession().getId();
			if ("on".equals(allSelectedVehicle)) {
				String REGISTER_KEY = "registerVehicleIds";
				List<Long> vehicleIdList = (List<Long>) super.getFromSession(
						REGISTER_KEY);
				if (vehicleIdList != null && vehicleIdList.size() >= 1) {
					TerminalCommand command = new TerminalCommand();
					command.setVehicleId(vehicleId);
					command.setCmdType(0x9101);
					command.setCmdData(sb.toString());
					for (long vId : vehicleIdList) {
						if (vId != vehicleId) {
							SendCommand(command, vId);

							VideoRequest v = new VideoRequest();
							v.setSimNo(command.getSimNo());
							v.setChannelId(channel);
							v.setStreamType(stream);
							v.setPlateNo(command.getPlateNo());
							v.setUserIp(this.getRequest().getRemoteAddr());
							v.setUserId(this.getOnlineUser().getEntityId());
							v.setUserName(this.getOnlineUser().getName());
							v.setSessionId(sessionId);
							v.setMediaType(videoDataType);
							onlineVideoRequestService.updateVideoRequest(v);
						}

					}
				}
			}

			TerminalCommand tc = new TerminalCommand();
			tc.setVehicleId(vehicleId);
			tc.setCmdType(0x9101);
			tc.setCmdData(sb.toString());
			SendCommand(tc);
			VideoRequest v = new VideoRequest();
			v.setSimNo(simNo);
			v.setChannelId(channel);
			v.setStreamType(stream);
			v.setPlateNo(tc.getPlateNo());
			v.setUserIp(this.getRequest().getRemoteAddr());
			v.setUserId(this.getOnlineUser().getEntityId());
			v.setUserName(this.getOnlineUser().getName());
			v.setSessionId(sessionId);
			v.setMediaType(videoDataType);
			onlineVideoRequestService.updateVideoRequest(v);

			return json(true, tc.getEntityId());
		} catch (Exception ex) {
			log.error(ex.getMessage(),ex);
			return json(false, ex.getMessage());
		}
	}


	@ResponseBody
	@RequestMapping("/stopBroadcast.action")
	public JsonMessage stopBroadcast(int vehicleId,String simNo, int channelId, String allSelectedVehicle) {
		try {
			String sessionId = this.getSession().getId();
			simNo = simNo.length() > 11 ? simNo.substring(1) : simNo;

			if ("on".equals(allSelectedVehicle)) {
				String REGISTER_KEY = "registerVehicleIds";
				List<Long> vehicleIdList = (List<Long>) super.getFromSession(
						REGISTER_KEY);
				if (vehicleIdList != null && vehicleIdList.size() >= 1) {
					for (long vId : vehicleIdList) {
						if (vId != vehicleId) {
							VehicleData vd = this.vehicleDataService.load(vId);
							if(vd != null)
							{
								onlineVideoRequestService.stopVideoRequest(this.getOnlineUser().getEntityId(),vd.getSimNo(), channelId, sessionId, 0,VideoDataType.BROADCAST);
								//TerminalCommand tc = onlineVideoRequestService.sendStopVideoTalkCommand(vd.getSimNo(), channelId);

							}
						}

					}
				}
			}

			//TerminalCommand tc =  onlineVideoRequestService.stopVideoRequest(this.getOnlineUser().getEntityId(),simNo, channelId, sessionId, 0,VideoDataType.BROADCAST);
			TerminalCommand tc = onlineVideoRequestService.sendStopVideoRealPlayRequestCommand(simNo, channelId);
			return json(true, tc == null ? 0: tc.getEntityId());
		} catch (Exception ex) {
			log.error(ex.getMessage(),ex);
			return json(false, ex.getMessage());
		}
	}


	@ResponseBody
	@RequestMapping("/stopRealTimeVideo.action")
	public JsonMessage stopRealTimeVideo(String simNo, int channelId, int streamType) {
		try {
			String sessionId = this.getSession().getId();
			simNo = simNo.length() > 11 ? simNo.substring(1) : simNo;
			int videoDataType = this.getUserPreference().getVideoDataType();
			onlineVideoRequestService.stopVideoRequest(this.getOnlineUser().getEntityId(),simNo, channelId, sessionId, streamType,videoDataType);
			return json(true,sessionId);
		} catch (Exception ex) {
			log.error(ex.getMessage(),ex);
			return json(false, ex.getMessage());
		}
	}


	/**
	 * 强行下发停止实时视频和视频回放的指令
	 * @param simNo
	 * @param channelId
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/stopVideoPlay.action")
	public JsonMessage stopVideoPlay(String simNo, int channelId) {
		try {
			String sessionId = this.getSession().getId();
			simNo = simNo.length() > 11 ? simNo.substring(1) : simNo;
			onlineVideoRequestService.sendStopVideoRealPlayRequestCommand(simNo, channelId);
			onlineVideoRequestService.sendStopVideoPlayBackCommand(simNo, channelId);
			return json(true,sessionId);
		} catch (Exception ex) {
			log.error(ex.getMessage(),ex);
			return json(false, ex.getMessage());
		}
	}



	/**
	 * 停止音频监听
	 * @param simNo
	 * @param channelId
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/stopListen.action")
	public JsonMessage stopListen(String simNo, int channelId) {
		try {
			String sessionId = this.getSession().getId();
			simNo = simNo.length() > 11 ? simNo.substring(1) : simNo;
			//TerminalCommand tc =  onlineVideoRequestService.stopVideoRequest(this.getOnlineUser().getEntityId(),simNo, channelId, sessionId, 0,VideoDataType.LISTEN);
			TerminalCommand tc = onlineVideoRequestService.sendStopVideoRealPlayRequestCommand(simNo, channelId);
			return json(true, tc == null ? 0: tc.getEntityId());
		} catch (Exception ex) {
			log.error(ex.getMessage(),ex);
			return json(false, ex.getMessage());
		}
	}


	@ResponseBody
	@RequestMapping("/stopTalk.action")
	public JsonMessage stopTalk(String simNo, int channelId) {
		try {
			String sessionId = this.getSession().getId();
			simNo = simNo.length() > 11 ? simNo.substring(1) : simNo;
			//TerminalCommand tc = onlineVideoRequestService.stopVideoRequest(this.getOnlineUser().getEntityId(),simNo, channelId, sessionId, 0,VideoDataType.TALK);
			TerminalCommand tc = onlineVideoRequestService.sendStopVideoTalkCommand(simNo, channelId);
			return json(true, tc == null ? 0: tc.getEntityId());
		} catch (Exception ex) {
			log.error(ex.getMessage(),ex);
			return json(false, ex.getMessage());
		}
	}


	/**
	@ResponseBody
	@RequestMapping("/stopBroadcast.action")
	public JsonMessage stopBroadcast(String simNo, int channelId) {
		try {
			String sessionId = this.getSession().getId();
			simNo = simNo.length() > 11 ? simNo.substring(1) : simNo;
			TerminalCommand tc = onlineVideoRequestService.stopVideoRequest(this.getOnlineUser().getEntityId(),simNo, channelId, sessionId, 0,VideoDataType.BROADCAST);
			//TerminalCommand tc = onlineVideoRequestService.sendStopVideoTalkCommand(simNo, channelId);
			return json(true, tc == null ? 0: tc.getEntityId());
		} catch (Exception ex) {
			log.error(ex.getMessage(),ex);
			return json(false, ex.getMessage());
		}
	}*/

	@ResponseBody
	@RequestMapping("/queryTerminalVideoProperty.action")
	public JsonMessage queryTerminalVideoProperty(long vehicleId) {
		try {
			TerminalCommand tc = new TerminalCommand();
			tc.setVehicleId(vehicleId);
			tc.setCmdType(0x9003);
			SendCommand(tc);

			return json(true, tc.getEntityId());
		} catch (Exception ex) {
			log.error(ex.getMessage(),ex);
			return json(false, ex.getMessage());
		}
	}


	@ResponseBody
	@RequestMapping("/getTerminalVideoProperty.action")
	public JsonMessage getTerminalVideoProperty(long commandId) {
		try {
			TerminalVideoProperty p = this.terminalVideoPropertyService.getTerminalVideoPropertyByCommandId(commandId);
			if(p != null)
			{
				String parentCode = "TerminalVideoProperty";
				Map<String, String> m = new HashMap<String, String>();
				String v = this.convert(""+p.getAudioEcnoderType(), "AudioEncoderType");
				m.put("audioEcnoderType", v);
				m.put("audioChannelNum", ""+p.getAudioChannelNum());

				v = this.convert(""+p.getAudioFrequence(), "AudioFrequency");
				m.put("audioFrequence", v);

				v = this.convert(""+p.getAudioSampleBitNum(), "AudioSampleBitNum");
				m.put("audioSampleBitNum", v);

				m.put("audioFrameLength", ""+p.getAudioFrameLength());

				m.put("supportAudio", p.getSupportAudio() == 1 ? "支持":"不支持");
				v = this.convert(""+p.getVideoEcnoderType(), "VideoEncoderType");
				m.put("videoEncoderType", v);

				m.put("maxAudioChannelNum", ""+p.getMaxAudioChannelNum());
				m.put("maxVideoChannelNum", ""+p.getMaxVideoChannelNum());
				return json(true, m);
			}

			return json(false, "终端没有应答，无法获取属性数据!");
		} catch (Exception ex) {
			log.error(ex.getMessage(),ex);
			return json(false, ex.getMessage());
		}
	}

	/**
	 * 获取指定车辆的通道下拉框
	 * @param vehicleId
	 * @return
	 */
	@RequestMapping("/getVehicleChannels.action")
	@ResponseBody
	public JsonMessage getVehicleChannels(long vehicleId) {
		try
		{
			VehicleData vd = this.vehicleDataService.load(vehicleId);
			int channleNum = vd.getVideoChannelNum();
			List results = new ArrayList();
			for(int m = 1; m <= channleNum; m++)
			{
				HashMap item = new HashMap();
				item.put("name", "通道"+m);
				item.put("code", ""+m);
				results.add(item);
			}
			return json(true, results);
		}catch (Exception ex) {
			log.error(ex.getMessage(),ex);
			return json(false, ex.getMessage());
		}
	}

	@RequestMapping("/getAllVehicleChannels.action")
	@ResponseBody
	public JsonMessage getAllVehicleChannels(@RequestParam(value = "vehicleId", defaultValue="0") long vehicleId, String simNo) {
		try
		{
			VehicleData vd = null;
			if(vehicleId > 0)
			  vd = this.vehicleDataService.load(vehicleId);
			else if(StringUtil.isNullOrEmpty(simNo) == false)
			{
				if(simNo.length() > 11)
					simNo = simNo.substring(simNo.length() - 11);
				vd = this.vehicleDataService.getVehicleBySimNo(simNo);
			}
			int channleNum = vd.getVideoChannelNum();
			List results = new ArrayList();
			for(int m = 1; m <= channleNum; m++)
			{
				HashMap item = new HashMap();
				item.put("name", vd.getPlateNo() + "  通道"+m);
				item.put("code", ""+m);
				results.add(item);
			}
			return json(true, results);
		}catch (Exception ex) {
			log.error(ex.getMessage(),ex);
			return json(false, ex.getMessage());
		}
	}





}
